﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WEB.Core.Controls;
using Ext.Net;
using WEB.Core.Util;
using log4net;
using WEB.BLL.Services;
using WEB.BLL.Entities;
using WEB.BLL;

namespace WEB.APP.Modules.List
{
    public partial class ListStudent : BasePage
    {
        public ListStudent()
            : base(SCREENS.USER, false)
        {
        }

        protected override void Page_Load(object sender, EventArgs e)
        {
            WindowEditor.SaveClick += WindowEditor_SaveClick;
            hdScreenDetailID.Text = SCREENS.STUDENTDETAIL;
            hdScreenImportID.Text = SCREENS.IMPORTSTUDENT;
            base.Page_Load(sender, e);
            LoadData();
            paddingBar.SetPageIndex(0);
        }

        void WindowEditor_SaveClick(object sender, EventArgs e)
        {
            ResourceManager.RegisterOnReadyScript("gr();");
        }
        protected void storeMain_OnRefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            LoadData();
        }

        protected void LoadData()
        {
            IList<StudentEntity> lstUser = StudentService.GetInstance().LoadData();
            if (null != lstUser)
            {
                this.storeMain.DataSource = lstUser;
                this.storeMain.DataBind();
                //e.Total = StudentE.TotalRow;
            }
        }

        public void btnAdd_Click(object sender, DirectEventArgs e)
        {
            this.WindowEditor.Show();
        }

        [DirectMethod]
        public void Edit(string UserName)
        {
            WindowEditor.Show(UserName);
        }
        [DirectMethod]
        public void Delete(int StudentId)
        {
            try
            {
                if (StudentId != 0)
                {
                    StudentService.GetInstance().Delete(new StudentEntity() { StudentId = StudentId });
                    this.storeMain.DataBind();
                }
            }
            catch (Exception ex)
            {
                Notification(ex);
            }
        }
    }
}
